<template>
	<view class="home-chat-input-panel">
		<view class="chat-chat-input-actions">
			<view class="chat-chat-input-action clickable" @click="clickChatModal">
				<uni-icons custom-prefix="iconfont" type="icon-renxiang"></uni-icons>
			</view>
			<view v-if="false" class="chat-chat-input-action clickable">
				<uni-icons custom-prefix="iconfont" type="icon-zidong"></uni-icons>
			</view>
		</view>
		<view class="home-chat-input-panel-inner">
			<textarea class="home-chat-input" v-model="messageContent" placeholder="Enter 发送, Shift + Enter 换行"
			          spellcheck="false" maxlength="9999"></textarea>
			<button class="button-icon-button home-chat-input-send clickable" @click="sendMessage">
				<view class="button-icon-button-icon">
					<uni-icons type="paperplane" size="20" color="white"></uni-icons>
				</view>
				<view class="button-icon-button-text">发送</view>
			</button>
		</view>
		<u-popup :show="showChatModal" mode="center">
			<z-chat-modal :chatBody="chatBody" @closeModal="closeChatModal"/>
		</u-popup>
	</view>
</template>

<script>
export default {
	emits: ["sendMessage"],
	props: {
		chatBody: {
			type: Object
		},
	},
	data() {
		return {
			showChatModal: false,
			messageContent: "",
		};
	},
	created() {
	},
	methods: {
		clickChatModal() {
			this.showChatModal = true;
		},
		closeChatModal() {
			this.showChatModal = false;
		},
		clearInputText() {
			this.messageContent = "";
		},
		sendMessage() {
			this.$emit("sendMessage", this.messageContent);
		},
		keyListener() {
			// #ifdef H5
			// 获得消息输入框对象
			let adjunctKeydown = false
			const textareaDom = document.querySelector('.home-chat-input-panel-inner textarea');
			if (textareaDom) {
				// 键盘按下时
				textareaDom.onkeydown = e => {
					if ([16, 17, 18, 93].includes(e.keyCode)) {
						// 按下了shift ctrl alt windows键
						adjunctKeydown = true;
					}
					if (e.keyCode === 13 && !adjunctKeydown) {
						e.preventDefault()
						// 执行发送
						setTimeout(() => {
							this.sendMessage();
						}, 300)
					}
				};
				textareaDom.onkeyup = e => {
					//松开adjunct键
					if ([16, 17, 18, 93].includes(e.keyCode)) {
						adjunctKeydown = false;
					}
				};
			}
			// #endif
		},
	}
}
</script>

<style lang="scss">

@import "../css/chat.scss";

.home-chat-input-panel {
	position: relative;
	width: 100%;
	padding: 10px 20px 20px;
	box-sizing: border-box;
	flex-direction: column;
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
	border-top: $border-in-light;
	box-shadow: $card-shadow;
}

.chat-chat-input-actions {
	display: flex;
	flex-wrap: wrap;
}

.home-chat-input-panel-inner {
	display: flex;
	flex: 1 1;
}

.chat-chat-input-actions .chat-chat-input-action:not(:last-child) {
	margin-right: 5px;
}

.chat-chat-input-actions .chat-chat-input-action {
	display: inline-flex;
	border-radius: 20px;
	font-size: 12px;
	background-color: $white;
	color: $black;
	border: $border-in-light;
	padding: 4px 10px;
	animation: home-slide-in .3s ease;
	box-shadow: $card-shadow;
	transition: all .3s ease;
	margin-bottom: 10px;
	align-items: center;
}

.home-chat-input {
	height: 60px;
	width: 100%;
	border-radius: 10px;
	border: $border-in-light;
	box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.03);
	background-color: $white;
	color: $black;
	font-family: inherit;
	padding: 10px 120px 10px 14px;
	resize: none;
	outline: none;
}

.home-chat-input-send {
	background-color: $primary;
	color: #fff;
	position: absolute;
	right: 30px;
	bottom: 32px;
}

</style>